package top.infopub.mgr.fia.service.impl;


import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.ProBudgetOfgroupDao;
import top.infopub.mgr.fia.dao.ProBudgetOfgroupDtlDao;
import top.infopub.mgr.fia.domain.ProBudgetOfgroupDomain;
import top.infopub.mgr.fia.service.ProBudgetOfgroupService;
import top.infopub.mgr.fia.vo.ProBudgetOfgroupVo;
import top.infopub.model.fia.ProBudgetOfgroup;
import top.infopub.model.fia.ProBudgetOfgroupDtl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


@Service
public class ProBudgetOfgroupServiceImpl extends GenericServiceImpl<ProBudgetOfgroup, String> implements ProBudgetOfgroupService {

    @Autowired
    private ProBudgetOfgroupDao proBudgetOfgroupDao;

    @Autowired
    private ProBudgetOfgroupDtlDao proBudgetOfgroupDtlDao;

    @Override
    public GenericDao<ProBudgetOfgroup, String> getDao() {
        return proBudgetOfgroupDao;
    }

    @Override
    public Page<ProBudgetOfgroupDomain> selectByDomainWhere(Page<ProBudgetOfgroupDomain> page,
                                                            ProBudgetOfgroupVo proBudgetOfgroupVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<ProBudgetOfgroupDomain>)proBudgetOfgroupDao.selectByDomainWhere(proBudgetOfgroupVo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveProBudgetOfgroup(ProBudgetOfgroup proBudgetOfgroup,
                                     List<ProBudgetOfgroupDtl> proBudgetOfgroupDtls) {
        proBudgetOfgroupDao.insertById(proBudgetOfgroup);

        if (CollectionUtils.isNotEmpty(proBudgetOfgroupDtls)) {
            proBudgetOfgroupDtlDao.insertByBatch(proBudgetOfgroupDtls);
        }

    }

    @Override
    public ProBudgetOfgroupVo queryById(String id) {
        return proBudgetOfgroupDao.queryById(id);
    }

    @Override
    public int count(Integer belongsYear, String hrOrgBillId) {
        return proBudgetOfgroupDao.count(belongsYear, hrOrgBillId);
    }

    /*@Override
    @Transactional(rollbackFor = Exception.class)
    public void udpProBudgetOfgroup(ProBudgetOfgroupVo proBudgetOfgroupVo) {

        ProBudgetOfgroup proBudgetOfgroup = proBudgetOfgroupDao.selectByPrimaryKey(proBudgetOfgroupVo.getId());
        BeanUtils.copyProperties(proBudgetOfgroupVo, proBudgetOfgroup);
        proBudgetOfgroup.setProcessStatus("9");//状态改为已生效
        proBudgetOfgroup.setUptTime(new Date());
        proBudgetOfgroup.setUptBy(SessionUserUtils.getSessionUserId());
        this.updateBySelective(proBudgetOfgroup);

    }*/

}